package vip.afeng.rpgserver.skill;

import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import vip.afeng.rpgserver.data.UpdateOne;
import vip.afeng.rpgserver.mapper.BasePropertyValueMapper;
import vip.afeng.rpgserver.mapper.NeigMapper;
import vip.afeng.rpgserver.mapper.UpdateOneMapper;

import javax.annotation.PostConstruct;

/**
 * @datetime: 2020/7/23 20:04
 * @project_name: afeng-rpg
 * @author: afeng
 */
@Data
@Component
public class Neig {
    /**
     * 内功等级
     */
    private int level;
    /**
     * 内功描述
     */
    private String description;

    /**
     * 内功数值
     */
    @Autowired
    private AbilityValue abilityData;

    @Autowired
    private BasePropertyValueMapper basePropertyValueMapper;

    @Autowired
    private UpdateOneMapper updateOneMapper;

    @Autowired
    private NeigMapper neigMapper;

    /**
     * 内功升级
     *
     * @param level
     */
    public void setLevel(int level) {
        this.level = level;
        UpdateOne updateOne = updateOneMapper.selectByPrimaryKey(1);
        abilityData.reSet(level, updateOne);
    }

    /**
     * 初始化
     */
    @PostConstruct
    public void init() {
        vip.afeng.rpgserver.data.Neig neig = neigMapper.selectByPrimaryKey(1);
        setDescription(neig.getDescription());
        abilityData.setBasePropertyValue(basePropertyValueMapper.selectByPrimaryKey(1));
        setLevel(0);
    }

    public String toString() {
        return "Neig(level=" + this.getLevel() + ", hp=" + this.getAbilityData().getHp() + ", mana=" + this.getAbilityData().getMana() +
                ", 体魄=" + this.getAbilityData().getTipo() + ", 身法=" + this.getAbilityData().getShenfa() + ", 闪避=" + this.getAbilityData().getShanbi() +
                ", description=" + this.getDescription() + ")";
    }
}
